
#include "SDL.h"
#include "SDL_ttf.h"
#include "SDL_mixer.h"

#include "dertmap.h"

#include <assert.h>

#include "SDLSurfaceCache.h"
#include "DertTerritory.h"

extern CSDLSurfaceCache DertTerritoryGraphics_g;


CDertTerritory::CDertTerritory(int x, int y, GeoType Type, int Player) : GameBase(x,y), m_GeoType(Type), m_PlayerNumber(Player), m_PlayerColorSurfaceNumber(0), m_GeoSurfaceNumber(0)
{
	SetPlayer(Player);
	
	// Setup Geo Surface Number
	switch(Type)
	{
	case(Forest):
		m_GeoSurfaceNumber = GEO_FOREST;
		break;
	case(Grass):
		m_GeoSurfaceNumber = GEO_GRASS;
		break;
	case(Mountain):
		m_GeoSurfaceNumber = GEO_MOUNTAIN;
		break;
	case(Water):
		m_GeoSurfaceNumber = GEO_WATER;
		break;
	default:
		assert(false);
		break;
	}
	assert(m_GeoSurfaceNumber);
}

CDertTerritory::~CDertTerritory()
{
}

// draw using SDLSurfaceCache
int CDertTerritory::Draw(SDL_Surface* pWorldSurface)
{
	// apply surface at position m_x, m_y
	//Temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Get the offsets from GameBase
    offset.x = m_x;
    offset.y = m_y;
    
    //Blit the surface
    SDL_BlitSurface( SURFACECACHE(m_PlayerColorSurfaceNumber), NULL, pWorldSurface, &offset );
	return SDL_BlitSurface( SURFACECACHE(m_GeoSurfaceNumber), NULL, pWorldSurface, &offset );
}

int CDertTerritory::Move(int x, int y)
{
	return 0;
}

// get appropriate surface number for player number
void CDertTerritory::SetPlayer(int Player)
{
	m_PlayerNumber = Player;
	
	switch(Player)
	{
	case(0):
		m_PlayerColorSurfaceNumber = P0_COLOR;
		break;
	case(1):
		m_PlayerColorSurfaceNumber = P1_COLOR;
		break;
	case(2):
		m_PlayerColorSurfaceNumber = P2_COLOR;
		break;
	default:
		assert(false);
		break;
	}
}

GameBase::ActionReturn CDertTerritory::Action(Event action,int inputX, int inputY)
{
	switch(action)
	{
	case(Select):
		// check for box hit
		if (inputX + 25 > m_x  )
		{
			if (inputX + 25 < m_x + 50)
			{
				if (inputY + 25 > m_y )
				{
					if (inputY + 25 < m_y + 50)
					{
						return Selected;
					}
				}
			}
		}
		break;
		
	case(Attack):
		break;
	}
	
	return NoReturn;
}

CDertTerritoryDynamic::CDertTerritoryDynamic(int x, int y, int SurfaceNumber, CDertTerritory* ObjRef) : GameBase (x,y), m_SurfaceNumber(SurfaceNumber), m_ObjRef(ObjRef)
{
}

CDertTerritoryDynamic::~CDertTerritoryDynamic()
{
}

// draw using SDLSurfaceCache
int CDertTerritoryDynamic::Draw(SDL_Surface* pWorldSurface)
{
	// apply surface at position m_x, m_y
	//Temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Get the offsets from GameBase
    offset.x = m_x;
    offset.y = m_y;
    
    //Blit the surface
	return SDL_BlitSurface( SURFACECACHE(m_SurfaceNumber), NULL, pWorldSurface, &offset );
}

int CDertTerritoryDynamic::Move(int x, int y)
{
	m_x = x;
	m_x = y;
	return 0;
}

GameBase::ActionReturn CDertTerritoryDynamic::Action(Event action,int inputX, int inputY)
{
	return NoReturn;
}
